package com.hghivln.blog.controller;


import com.hghivln.blog.common.lang.Result;
import com.hghivln.blog.pojo.dto.BlogCollectionDto;
import com.hghivln.blog.service.BlogCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户_博客收藏表 前端控制器
 * </p>
 *
 * @author hghivln
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/blog-collection")
public class BlogCollectionController {

    @Autowired
    private BlogCollectionService blogCollectionService;

    /**
     * 收藏
     */
    @PostMapping("/collection/{blogId}")
    public Result<?> goods(@PathVariable Long blogId) {
        System.out.println(blogId);
        blogCollectionService.collection(blogId);
        return new Result<>("收藏成功");
    }

    /**
     * 查询博客是否收藏
     */
    @GetMapping("/getCollection/{blogId}")
    public Result<?> getGoods(@PathVariable Long blogId) {
        System.out.println(blogId);
        Integer count = blogCollectionService.getCollection(blogId);
        return new Result<>(count);
    }

    /**
     * 取消收藏
     */
    @PostMapping("/cancelCollection/{blogId}")
    public Result<?> cancelCollection(@PathVariable Long blogId) {
        blogCollectionService.removeByBlogId(blogId);
        return new Result<>("取消收藏成功");
    }

    /**
     * 用户的收藏
     */
    @PostMapping("/getByPage")
    public Result<?> getByPage(@RequestBody BlogCollectionDto blogCollectionDto) {
        return blogCollectionService.getByPage(blogCollectionDto);
    }
}
